import heapq
import collections
class StockPrice(object):

    def __init__(self):
        self.p = collections.defaultdict(int)
        self.max_st = []
        self.min_st = []
        self.latest_time = -1


    def update(self, timestamp, price):
        """
        :type timestamp: int
        :type price: int
        :rtype: None
        """
        self.p[timestamp] = price
        self.latest_time = max(self.latest_time, timestamp)
        heapq.heappush(self.min_st, [price, timestamp])
        heapq.heappush(self.max_st, [-price, timestamp])

    def current(self):
        """
        :rtype: int
        """
        return self.p[self.latest_time]



    def maximum(self):
        """
        :rtype: int
        """
        while self.p[self.max_st[0][1]] != -self.max_st[0][0]:
            heapq.heappop(self.max_st)
        return - self.max_st[0][0]




    def minimum(self):
        """
        :rtype: int
        """
        while self.p[self.min_st[0][1]] != self.min_st[0][0]:
            heapq.heappop(self.min_st)
        return self.min_st[0][0]
